package com.sxm.yiwei.activitis;

import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AlertDialog;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.Toast;

import com.sxm.yiwei.R;

import java.util.ArrayList;
import java.util.List;

public class HomeMakeMoneyActivity extends BaseActivity {


    private ViewPager howPager;
    private List<View> imgs ;
    private ImageView makemoneyback;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_fw_help);
        makemoneyback = (ImageView) findViewById(R.id.makemoney_back);
        makemoneyback.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        howPager = (ViewPager) findViewById(R.id.home_howpager);
        imgs = new ArrayList<>();
        imgs.add(getLayoutInflater().inflate(R.layout.pagerone,null));
        imgs.add(getLayoutInflater().inflate(R.layout.pagertwo,null));
        imgs.add(getLayoutInflater().inflate(R.layout.pagerthree,null));
        imgs.add(getLayoutInflater().inflate(R.layout.pagerfour,null));
        imgs.add(getLayoutInflater().inflate(R.layout.pagerfive,null));
        howPager.setAdapter(new MyAdapter(imgs,this));

    }

    class MyAdapter extends PagerAdapter{
        List<View> imgs;
        Context context;
        public MyAdapter(List<View> imgs, Context context) {
            this.imgs=imgs;
            this.context=context;
        }

        @Override
        public int getCount() {
            return imgs.size();
        }

        @Override
        public boolean isViewFromObject(View view, Object object) {
            return view==object;
        }
        @Override
        public void destroyItem(ViewGroup container, int position, Object object) {
           // super.destroyItem(container, position, object);
            container.removeView((View) object);
        }

        @Override
        public int getItemPosition(Object object) {
            return super.getItemPosition(object);
        }

        @Override
        public Object instantiateItem(ViewGroup container, int position) {
                container.addView(imgs.get(position));
                if (position==imgs.size()-1){
                    Toast.makeText(context, "最后一页", Toast.LENGTH_SHORT).show();
                }else if (position==0){

                }
            return imgs.get(position);
        }

    }
}
